# 列表推导式

"""
格式：
[表达式  for  变量 in OldList]   or [表达式  for 变量 in  oldList if 条件 ]

列表推导式 赛高


"""
import random

names = ['a', 'b', 'c', 'dqw', 'e', 'asd', 'ertqw']
result = [name for name in names if len(name) > 3]
print(result)

result = [name.capitalize() for name in names if len(name) > 3]
print(result)

newlist = [i for i in list(range(1, 101)) if i % 3 == 0 and i % 5 == 0]
print(newlist)

print('&' * 50)

#  集合推导式
list11 = [1, 2, 3, 4, 51, 15, 4, 5, 2, 1, 2, 3]
set1 = {x for x in list11}
print(set1)

print(list11.reverse())

# 字典推导式
dict1 = {'a': 'A', 'b': 'B', 'c': "B", 'cc': "A"}

print(dict1)

newDict = {value: key for key, value in dict1.items()}
print(newDict)

randomNumber = [random.randint(10, 100) for i in range(10)]
print(randomNumber)

name = ['1', '2', '3', '4', '5', '6']
name1 = ['a', 'b', 'c', 'd', 'e', 'f']

# zip函数用法 两个列表生成 dict
print(dict(zip(name, name1)))
